/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package descentserver;

import com.esotericsoftware.kryonet.Connection;
import com.esotericsoftware.kryonet.Listener;
import descentserver.Packet.*;
import org.newdawn.slick.util.Log;

/**
 *
 * @author jimmy
 */
public class NetworkListener extends Listener {


    @Override
    public void connected(Connection cnctn) {
        Log.info("Someone has connected");
    }


    @Override
    public void disconnected(Connection cnctn) {
        Log.info("Someone has disconnected");
    }


    @Override
    public void received(Connection cnctn, Object o) {
        
        if(o instanceof PacketLoginRequest){
            PacketLoginAccepted p = new PacketLoginAccepted();
            p.accepted = true;
            cnctn.sendTCP(p);
        
        }
        
        if (o instanceof PacketMessage){
            String message = ((PacketMessage) o).message;
            Log.info(message);
            PacketMessage m = new PacketMessage();
            m.message = "Message was Recieved from the server";
            Log.info(m.toString());
            cnctn.sendTCP(m);
            
            
        }
        
    }
    

    
}
